import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Description:
 * Date: 2025-11-06
 * Time: 20:39
 */
public class CardDemo {
    public static final String[] suit = {"♦","♣","♥","♠"};

    //买一副牌(定义52张牌)  在Card这个类上进行加工
    public List<Card> buyCard() {
        List<Card> cardList = new ArrayList<>();
        int len = suit.length;
        //定义花色
        for (int i = 0; i < len; i++) {
            String color = suit[i];
            //定义数字
            for (int j = 1; j < 14; j++) {
                //得到一张牌
                Card card = new Card(color,j);
                cardList.add(card);
            }
        }
        return cardList;
    }

    private void swap (List<Card> cardList,int i, int j) {
        /*
         * Card card = cardList[i];
         * cardList[i] = cardList[j];
         * cardList[j] = card;
         * */
        Card tmp1 = cardList.get(i);
        Card tmp2 = cardList.get(j);
        cardList.set(i,tmp2);
        cardList.set(j,tmp1);
    }

    //洗牌
    public List<Card> shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }

        return cardList;
    }



}
